import requests


class IHRMApi:
    # 封装登录接口
    @classmethod
    def ihrm_login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 封装添加员工接口
    @classmethod
    def ihrm_add(cls, token, add_body):
        Add_to_url = "http://ihrm2-test.itheima.net/api/sys/user"
        Add_to_header = {"Content-Type": "application/json", "Authorization": token}
        Add_to_resp = requests.post(url=Add_to_url, headers=Add_to_header, json=add_body)
        return Add_to_resp

    # 封装查询员工接口
    @classmethod
    def ihrm_Inquire(cls, emp_id, token):
        Inquire_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        Inquire_header = {"Authorization": token}
        Inquire_resp = requests.get(url=Inquire_url, headers=Inquire_header)
        return Inquire_resp

    # 封装修改员工接口
    @classmethod
    def ihrm_Revise(cls, emp_id, token, Revise_body):
        Revise_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        Revise_header = {"Content-Type": "application/json", "Authorization": token}
        Revise_resp = requests.put(url=Revise_url, headers=Revise_header, json=Revise_body)
        return Revise_resp

    # 封装删除员工接口
    @classmethod
    def ihrm_delete(cls, emp_id, token):
        delete_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        delete_header = {"Authorization": token}
        delete_resp = requests.delete(url=delete_url, headers=delete_header)
        return delete_resp


if __name__ == '__main__':
    token = '82ec6bb4-0823-463c-b2f4-1407aca4758c'
    add_body = {
        "username": "小猪佩奇",
        "mobile": "15112312145",
        "workNumber": "22"
    }
    resp = IHRMApi.ihrm_add(token, add_body)
    print('resp=',resp.json())
